package com.salim.leetcode.$231;

/**
 * Created with IntelliJ IDEA.
 * User: clevo
 * Date: 15-7-10
 * Time: 下午5:09
 * To change this template use File | Settings | File Templates.
 */
public class PowerOfTwo {
    int[] array = {1,2,4,8,16,32,64,128,256,512,1024,2048,
            4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,
            4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,
            1073741824};


    public boolean isPowerOfTwo(int n) {
        String binaryStr = Integer.toBinaryString(n).toString();
        if(n > 0){
            if(binaryStr.indexOf("1") == binaryStr.lastIndexOf("1")){
                return true;
            }
        }
        return false;

        /*int count = 0;
        while (n > 0) {
            count += (n & 1);
            n >>= 1;
        }
        return count == 1;*/


    }

    public static void main(String[] args){

        int j = 1;
        for(int i=0;i<32;i++){
            System.out.println(j);
            System.out.println(Integer.toBinaryString(j));
            j= j <<1 ;
        }
    }
}
